var ajaxUrl = require('../../utils/url.js')
Page({
  data: {
    categoryId: 0,
    listData: [],
    hidden: false,
    scrollHeight: 0,
    current: 1,
    size: 10,
    pages: 1,
    category: [{label: '中国',id:'1', color: ''},{label: '泰国',id:'2'},{label:'缅甸', id:'3'},{label: '越南',id: '4'}]
  },
  onLoad: function( option ) {
    this.setData({
      categoryId: option.id
    });
    this.fetchData()
  },
  onShow: function (option) {
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          scrollHeight: res.windowHeight
        });
      }
    })
  },
  fetchData () {
    var self = this;
    self.setData({
      hidden: false
    });
    wx.request({
      method:"POST",
      url: ajaxUrl.goodsList(),
      data: {
        category: parseInt(self.data.categoryId),
        currentPage: self.data.current,
        pageSize: self.data.size
      },
      success: function(res) {
        if(res.data.code === 200){
          self.setData({
            'listData' : self.data.listData.concat(res.data.data),
          })
        }else{
          console.log(res.data.msg)
        }
        setTimeout(function () {
          self.setData({
            hidden: true
          });
        }, 300);
      }
    })
  },
  lower (e) {
    var self = this;
    self.setData({
      current: self.data.current + 1
    });
    self.fetchData();
  }
})